﻿using System.Linq;
using FacialClub.Models.Entities;
using FacialClub.Models.Interfaces;
namespace FacialClub.Models.Repositories
{
    /// <summary>
    /// Customer Type Repository
    /// </summary>
    public class CustomerTypeRepository : ICustomerTypeRepository
    {
        readonly FacialClubEntities _db = new FacialClubEntities();

        /// <summary>
        /// Get Customer Type Details by Title
        /// </summary>
        /// <param name="strQuery"></param>
        /// <returns></returns>
        public IQueryable<CustomerType> FindCustomerTypeByName(string strQuery)
        {
            return _db.CustomerTypes.Where(d => d.CustomerTypeName.Contains(strQuery));
        }

        /// <summary>
        /// Get All Customer Type
        /// </summary>
        /// <returns></returns>
        public IQueryable<CustomerType> FindAllCustomerType()
        {
            return _db.CustomerTypes;
        }

        /// <summary>
        /// Get Customer Type by Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public CustomerType GetCustomerTypeById(int id)
        {
            return _db.CustomerTypes.SingleOrDefault(d => d.CustomerTypeId == id);
        }

        /// <summary>
        /// Add Customer Type in the Database
        /// </summary>
        /// <param name="customerType"></param>
        public void Add(CustomerType customerType)
        {
            _db.CustomerTypes.AddObject(customerType);
        }

        /// <summary>
        /// Delete Customer Type from Database
        /// </summary>
        /// <param name="customerType"></param>
        public void Delete(CustomerType customerType)
        {
            _db.CustomerTypes.DeleteObject(customerType);
        }

        /// <summary>
        /// Save Customer Type in the database
        /// </summary>
        public void Save()
        {
            _db.SaveChanges();
        }
    }
}